<?php
/**
 * @copyright (C)2020-2099 Hnaoyun Inc.
 * @author XingMeng
 * @email hnxsh@foxmail.com
 * @date 2020年3月8日
 *  个人扩展标签可编写到本类中，升级不会覆盖
 */
namespace app\home\controller;

use core\basic\Controller;

class ExtLabelController
{

    protected $content;

    /* 必备启动函数 */
    public function run($content)
    {
        // 接收数据
        $this->content = $content;
        
        // 执行个人自定义标签函数
        $this->test();
        
        // 返回数据
        return $this->content;
    }

    // 测试扩展单个标签
    private function test()
    {
        $this->content = str_replace('{pboot:userip}', get_user_ip(), $this->content);
    }


    // 通过QQ号即可获取用户信息 @mk-qqinfo
    public function qqinfo()
    {
        $QQ=$_GET["qq"];
        $time=time();
        if($QQ!=''){
            $urlPre = 'https://r.qzone.qq.com/fcg-bin/cgi_get_portrait.fcg?g_tk=1518561325&uins=';
            $data = common_curl($urlPre.$QQ);
            $data = iconv("GB2312","UTF-8",$data);
            $pattern = '/portraitCallBack\((.*)\)/is';
            preg_match($pattern,$data,$result);
            $result = $result[1];
            $nickname = json_decode($result, true)["$QQ"][6];
            $email = $QQ."@qq.com";
            $headimg = "https://q1.qlogo.cn/g?b=qq&nk=$QQ&s=100&t=".$time;
            return "{\"nickname\":\"$nickname\",\"touxiang\":\"$headimg\",\"email\":\"$email\"}";
        }else{
            return "请输入qq号！";
        }
    }
}
